part of './SMyTextView.dart';


// 文本生命周期监听


class ControllerTextView with WidgetsBindingObserver{

  _SMyTextViewState state ;
  MyYSTextView androidController;

  /// Android构造器
  ControllerTextView.android(MyYSTextView _androidController, _SMyTextViewState _state) {
    WidgetsBinding.instance.addObserver(this);
    androidController = _androidController;
    state = _state;
  }


  Future<void> dispose() async {

    await androidController?.onPause();
    await androidController?.onDestroy();

    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    debugPrint('didChangeAppLifecycleState: $state');
    // 因为这里的生命周期其实已经是App的生命周期了, 所以除了这里还需要在dispose里释放资源
    switch (state) {
      case AppLifecycleState.resumed:
        androidController?.onResume();
        break;
      case AppLifecycleState.inactive:
        break;
      case AppLifecycleState.paused:
        androidController?.onPause();
        break;
      case AppLifecycleState.detached:
        androidController?.onDestroy();
        break;
    }
  }








}